from rest_framework.generics import ListAPIView
from rest_framework.permissions import IsAdminUser
from rest_framework.viewsets import ModelViewSet

from goods.models import GoodsChannel, GoodsChannelGroup, GoodsCategory
from meiduo_admin.serializer.channels import ChannelsSerializer, ChannelGroupSerializer, ChannelCategoriesSerializer


class ChannelViewSet(ModelViewSet):
    permission_classes = [IsAdminUser]
    queryset = GoodsChannel.objects.all()

    serializer_class = ChannelsSerializer


class ChannelTypesView(ListAPIView):
    permission_classes = [IsAdminUser]
    queryset = GoodsChannelGroup.objects.all()
    serializer_class = ChannelGroupSerializer

    pagination_class = None


class ChannelCategoriesView(ListAPIView):
    pagination_class = [IsAdminUser]
    queryset = GoodsCategory.objects.filter(parent=None)
    serializer_class = ChannelCategoriesSerializer

    pagination_class = None
